package authentication.module;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.UnsupportedCallbackException;

public class SubjectCallbackHandler implements CallbackHandler {

	@Override
	public void handle(Callback[] subjectCallbackArray) throws IOException,
			UnsupportedCallbackException {
		NameCallback cnpCallback = null;
		int counter = 0;
		while (counter < subjectCallbackArray.length) {
			if (subjectCallbackArray[counter] instanceof NameCallback) {
				cnpCallback = (NameCallback) subjectCallbackArray[counter++];
				System.out.println(cnpCallback.getPrompt());
				cnpCallback.setName((new BufferedReader(new InputStreamReader(
						System.in))).readLine());
			}
		}
	}

}
